--Redzone RPG
--By Kylegar


rzItem = {}

ItemClasses = {}
ItemsActive = {}
--[[
NON META FUNCTIONS
These are for creating and finding Items
--]]

function rzItem.RegisterItem(item)	
	table.insert(ItemClasses,item)
end


function rzItem.Create(classname)
	for k,v in pairs(ItemClasses) do
		if (table.HasValue(v, classname)) then
			local newitem = table.Copy(v)
			setmetatable(newitem , self)
			self.__index = self
			newitem.ItemID = #ItemsActive + 1
			table.insert(ItemsActive , newitem)
			newitem:Init()
			return 	newitem
		end
	end
end

function ShowItemClasses()
Msg("Items: \n")
	for k,v in pairs(ItemClasses) do
		Msg("  "..k.." "..type(v).."\n")
		for e,r in pairs(v) do
			Msg("    "..e.." ["..type(r).."] "..tostring(r).."\n")
				
		end
	end
end

function rzItem.FindAll()
	return ItemsActive
end


function rzItem.FindByClass(classname)
	local ItemBuff = {}
	for k,v in pairs(ItemsActive) do
		if(table.HasValue(v , classname)) then
			table.insert(ItemBuff , v)
		end
		
	end
	return ItemBuff
end


function rzItem.FindByItemID(itemID)
	local ItemBuff = {}
	for k,v in pairs(ItemsActive) do
		if(table.HasValue(v , itemID)) then
			table.insert(ItemBuff , v)
		end	
	end
	return ItemBuff		
end

function rzItem.FindItemsOnGround()
	local ItemBuff = {}
	for k,v in pairs(ItemsActive) do
		if(v:IsOnGround()) then
			table.insert(ItemBuff , v)
		end
	end
	return ItemBuff	
end

